<template>
  <div id="index">
    <transition :name="transitionName">
      <router-view class="index_center"></router-view>
    </transition>
    <footer-app></footer-app>
  </div>
</template>

<script>
  export default {
    name: "index",
    data() {
      return {
        transitionName: ""
      }
    },
    watch: { //使用watch 监听$router的变化
      $route(to, from) {
        //如果to索引大于from索引,判断为前进状态,反之则为后退状态
        if (to.meta.index > from.meta.index) {
          //设置动画名称
          this.transitionName = 'slide-left';
        } else {
          this.transitionName = 'slide-right';
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  #index {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-items: center;
    align-content: center;
    position: relative;

    .index_center {
      width: 100%;
      height: 100%;
      overflow: auto;
      padding-bottom: 50px;
      box-sizing: border-box;
    }

    .slide-right-enter-active,
    .slide-right-leave-active,
    .slide-left-enter-active,
    .slide-left-leave-active {
      will-change: transform;
      transition: all 500ms;
      position: absolute;
    }
    .slide-right-enter {
      opacity: 0;
      transform: translate3d(-100%, 0, 0);
    }
    .slide-right-leave-active {
      opacity: 0;
      transform: translate3d(100%, 0, 0);
    }
    .slide-left-enter {
      opacity: 0;
      transform: translate3d(100%, 0, 0);
    }
    .slide-left-leave-active {
      opacity: 0;
      transform: translate3d(-100%, 0, 0);
    }

  }

</style>
